<?php
	include("../includes/main_inc.php");
	
	if($_GET['id']) $id=$_GET['id'];
	elseif ($_POST['id']) $id=$_POST['id'];
	
	if($_POST['Submit']){
		//if($_POST['password']==$_POST['password2']){
			$m= new UpdateDatabase();
			$m->AddPosts($_POST,$_FILES);
			$m->AddSkip(array("id"));
			$m->AddTable("affiliate");
			$m->AddID($_POST['id']);
			$m->DoStuff();
			$Message="Member Updated";
			
			if($_POST['Submit']=='Approve'){
				if(is_array($_POST['DFiles'])){
					foreach($_POST['DFiles'] as $val){
						$rslt=$r->RawQuery("DELETE FROM affiliateJoinedPrograms WHERE affiliateID=$id AND affiliateProgramsID=$val");
						if(!$rslt) print mysql_error();
						$rslt=$r->RawQuery("INSERT INTO affiliateJoinedPrograms (affiliateID,affiliateProgramsID,Status) VALUES ($id,$val,'Approved')");
						if(!$rslt) print mysql_error();
					}
				}
			}
			if($_POST['Submit']=='Reject'){
				if(is_array($_POST['DFiles'])){
					foreach($_POST['DFiles'] as $val){
						$r->RawQuery("DELETE FROM affiliateJoinedPrograms WHERE affiliateID=$id AND affiliateProgramsID=$val");
						$r->RawQuery("INSERT INTO affiliateJoinedPrograms (affiliateID,affiliateProgramsID,Status) VALUES ($id,$val,'Rejected')");
					}
				}
			}
		//};
	};
	
	
	
	
	
	$PInsert=array();
	$PStatus=array();
	$r->AddTable("affiliate");
	$r->AddSearchVar($id);
	$Insert=$r->GetRecord();
	$rslt=$r->RawQuery("SELECT affiliateProgramsID,Status FROM affiliateJoinedPrograms WHERE affiliateID=$id");
	while($data= mysql_fetch_row($rslt)){
		$PInsert[]=$data[0];
		$PStatus[]=$data[1];
	}

?><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Affiliate Bubble Administration</title>

<link href="<?=$rootdir?>css/admin.css" rel="stylesheet" type="text/css">
<script src="<?=$rootdir?>jscript/menuArray.js" language="javascript"></script>
<script src="<?=$rootdir?>jscript/clock.js" language="javascript"></script></head>

<body onLoad="funClock();">
<?php include("../includes/header.php"); ?>
<table width="100%" border="0" cellspacing="25" cellpadding="0">
<tr>
<td valign="top" width="240"><div id="menu">
  <?php include("../menu/affiliatesmenu.php"); ?>
</div></td>
<td align="center" valign="top">

<div id="titleCompact">
  <form action="modify.php" method="post">
  <table width="100%" border="0" cellpadding="5" cellspacing="1" bgcolor="#E9EEF5">
    <tr id="formHeader2">
      <td><strong>Modify Affiliate Account Details </strong><strong></strong>
          <?=$Message;?></td>
    </tr>
    <tr>
      <td align="center" bgcolor="#FFFFFF"><table width="400" border="0" cellspacing="0" cellpadding="4">
          <tr>
            <td width="130" height="30">Company Name:</td>
            <td width="354"><input name="companyName" type="text" class="formFields" id="companyName" value="<?=$Insert['companyName'];?>" size="40"></td>
          </tr>
          <tr>
            <td height="30">Contact Name:</td>
            <td><input name="contactName" type="text" class="formFields" id="contactName" value="<?=$Insert['contactName'];?>" size="40"></td>
          </tr>
          <tr>
            <td height="30">Email Address: </td>
            <td><input name="email" type="text" class="formFields" id="email" value="<?=$Insert['email'];?>" size="40"></td>
          </tr>
          <tr>
            <td height="30">Phone:</td>
            <td><input name="phone" type="text" class="formFields" id="phone" value="<?=$Insert['phone'];?>" size="40"></td>
          </tr>
          <tr>
            <td height="30">Username:</td>
            <td><input name="username" type="text" class="formFields" id="username" value="<?=$Insert['username'];?>" size="40"></td>
          </tr>
          <tr>
            <td>Password:</td>
            <td><input name="password" type="password" class="formFields" id="password" value="<?=$Insert['password'];?>" size="40"></td>
          </tr>
          <tr>
            <td>Confirm Password:</td>
            <td><input name="password2" type="password" class="formFields" id="password2" value="<?=$Insert['password'];?>" size="40"></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td><input name="Submit" type="submit" id="Submit" value="Modify Account Details" class="formButtonSubmit"></td>
          </tr>
      </table></td>
    </tr>
  </table>
  <br>
  <br>
  <table width="100%" border="0" cellpadding="5" cellspacing="1" bgcolor="#E9EEF5">
    <tr id="formHeader">
      <td><strong>Programs Status </strong><strong></strong></td>
    </tr>
    <tr>
      <td align="center" bgcolor="#FFFFFF"><br>
        <table width="412" border="0" cellpadding="5" cellspacing="1" bgcolor="#E9EEF5">
          <tr id="formHeader">
            <td width="439"><strong>Name </strong></td>
            <td width="84" align="center"><strong>Status</strong></td>
            <td width="40" align="center"><strong>Join</strong></td>
          </tr>
          <?php
	$Count=0;
	$r=new ReturnRecord();
	$sq2=$r->rawQuery("SELECT id,Name FROM affiliatePrograms");  
	while ($myrow = mysql_fetch_row($sq2)) {
?>
          <tr bgcolor="<?=(($Count%2)==0 ? "#FFFFFF" : "#EBEBEB"); ?>">
            <td><?=$myrow[1];?></td>
            <td align="center">
			<?
			$pkey=array_search($myrow[0],$PInsert);
			if($pkey){
				print $PStatus[$pkey];
			}else{
				?>Not Joined<?
			}
			?>			</td>
            <td align="center"><input name="DFiles[]" type="checkbox" id="DFiles[]" value="<?=$myrow[0];?>"></td>
          </tr>
          <?
		$Count++;
	};
?>
          <tr>
            <td colspan="2" bgcolor="#FFFFFF"><input name="Submit" type="submit" id="Submit" value="Approve" class="formButtonSubmit"></td>
            <td align="center" bgcolor="#FFFFFF"><input name="Submit" type="submit" id="Submit" value="Reject" class="formButtonSubmit"></td>
          </tr>
        </table>
        </td>
      </tr>
  </table>
  <br>
  <table width="100%" border="0" cellpadding="5" cellspacing="1" bgcolor="#E9EEF5">
    <tr id="formHeader">
      <td><strong>Modify Payment Details </strong><strong></strong></td>
    </tr>
    <tr>
      <td align="center" bgcolor="#FFFFFF"><table width="400" border="0" cellspacing="0" cellpadding="4">
          <tr>
            <td width="130" height="30">Select Payment Method:</td>
            <td width="354"><select name="select" class="formFields"  id="select" onChange="SetPaymentType()">
                <option value="Deposit" <?=($Insert['paymentMethod']=="Deposit" ? "selected" :"");?>>Direct Deposit</option>
                <option value="Cheque" <?=($Insert['paymentMethod']=="Cheque" ? "selected" :"");?>>Pay By Cheque</option>
              </select>
            </td>
          </tr>
          <tr id="bankRow1">
            <td height="30">Bank Name: </td>
            <td><input name="bankName2" type="text" class="formFields" id="bankName2" value="<?=$Insert['bankName'];?>" size="40"></td>
          </tr>
          <tr id="bankRow2">
            <td height="30">Name On Account: </td>
            <td><input name="bankAccount2" type="text" class="formFields" id="bankAccount2" value="<?=$Insert['bankAccount'];?>" size="40"></td>
          </tr>
          <tr id="bankRow3">
            <td height="30">BSB:</td>
            <td><input name="bankBsb2" type="text" class="formFields" id="bankBsb2" value="<?=$Insert['bankBsb'];?>" size="40"></td>
          </tr>
          <tr id="bankRow4">
            <td height="30">Account Number: </td>
            <td><input name="bankNumber2" type="text" class="formFields" id="bankNumber2" value="<?=$Insert['bankNumber'];?>" size="40"></td>
          </tr>
          <tr id="chqRow1">
            <td height="30">Address</td>
            <td><input name="chqAddress2" type="text" class="formFields" id="chqAddress2" value="<?=$Insert['chqAddress'];?>" size="40"></td>
          </tr>
          <tr id="chqRow2">
            <td height="30">Suburb</td>
            <td><input name="chqSuburb2" type="text" class="formFields" id="chqSuburb2" value="<?=$Insert['chqSuburb'];?>" size="40"></td>
          </tr>
          <tr id="chqRow3">
            <td height="30">State</td>
            <td><input name="chqState2" type="text" class="formFields" id="chqState2" value="<?=$Insert['chqState'];?>" size="40"></td>
          </tr>
          <tr id="chqRow4">
            <td height="30">Country</td>
            <td><input name="chqCountry2" type="text" class="formFields" id="chqCountry2" value="<?=$Insert['chqCountry'];?>" size="40"></td>
          </tr>
          <tr id="chqRow5">
            <td height="30">PostCode</td>
            <td><input name="chqPostcode2" type="text" class="formFields" id="chqPostcode2" value="<?=$Insert['chqPostcode'];?>" size="40"></td>
          </tr>
          <tr id="chqRow6">
            <td height="30">Name On Cheque</td>
            <td><input name="chqName2" type="text" class="formFields" id="chqName2" value="<?=$Insert['chqName'];?>" size="40"></td>
          </tr>
          <tr>
            <td height="30">GST:</td>
            <td><input name="gst2" type="checkbox" id="gst2" value="1" <?=($Insert['gst']==1 ? "checked" :"");?>>
              I am eligible to collect GST </td>
          </tr>
          <tr>
            <td>ABN:</td>
            <td><input name="abn2" type="text" class="formFields" id="abn2" value="<?=$Insert['abn'];?>" size="40"></td>
          </tr>
          <tr>
            <td><input name="id" type="hidden" id="id" value="<?=$id;?>"></td>
            <td><input name="Submit" type="submit" id="Submit" value="Modify Payment Details" class="formButtonSubmit"></td>
          </tr>
      </table></td>
    </tr>
  </table>
  </form>
</div>

<div id="contentCompact"></div>

</td>
</tr>
</table>
</body>
</html>
